//
//  RecommentView.m
//  CaiPiao
//
//  Created by apple on 2018/5/21.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "RecommentView.h"

@implementation RecommentView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


-(void)addNumberToNumberBoxViewsWith:(NSString*)currentID andCallBack:(void(^)(NSString* numberString))callBcakBlock{
    for (UIView* view in self.subviews) {
        [view removeFromSuperview];
    }
    CGFloat ballWidth = 35;
    CGFloat spacing = 6;
    CGFloat spacingX = 0;
    NSArray* redArray = [[SelectionNumManager shared] randomRedNumberActionWithLottoryID:currentID];
    NSArray* blueArray = [[SelectionNumManager shared] randomBlueNumberActionWithLottoryID:currentID];
    for (int i=0; i<[redArray count]; i++) {
        UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(i*(ballWidth+spacing), 0, ballWidth, ballWidth)];
        numberView.backgroundColor = [UIColor colorWithRed:(255.0/255.0) green:(90/255.0) blue:0 alpha:1];
        UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ballWidth, ballWidth)];
        numberLabel.font = [UIFont boldSystemFontOfSize:15];
        numberLabel.textColor = [UIColor whiteColor];
        numberLabel.textAlignment = NSTextAlignmentCenter;
        numberLabel.text = [redArray objectAtIndex:i];
        [numberView addSubview:numberLabel];
        numberView.layer.cornerRadius = ballWidth*0.5;
        [self addSubview:numberView];
        spacingX+=(ballWidth+spacing);
    }
    for (int i=0; i<[blueArray count]; i++) {
        UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(spacingX, 0, ballWidth, ballWidth)];
        numberView.backgroundColor = [UIColor colorWithRed:(68.0/255.0) green:(160/255.0) blue:(255.0/255.0) alpha:1];
        UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ballWidth, ballWidth)];
        numberLabel.font = [UIFont boldSystemFontOfSize:15];
        numberLabel.textColor = [UIColor whiteColor];
        numberLabel.textAlignment = NSTextAlignmentCenter;
        numberLabel.text = [blueArray objectAtIndex:i];
        [numberView addSubview:numberLabel];
        numberView.layer.cornerRadius = ballWidth*0.5;
        [self addSubview:numberView];
        spacingX+=(ballWidth+spacing);
    }
    
    
    NSString* redString = [redArray componentsJoinedByString:@","];
    NSString* blueString = [blueArray componentsJoinedByString:@","];
    NSString* numberString = @"";
    numberString = redString;
    if ([blueString length]>0) {
        numberString = [NSString stringWithFormat:@"%@+%@",numberString,blueString];
    }
    
    if (callBcakBlock) {
        callBcakBlock(numberString);
    }
}

@end
